/**
 * Project Name:jfinal_demo6
 * File Name:FormValidator.java
 * Package Name:com.demo.validator
 * Author:郑 鸿
 * Date:2017年1月3日下午9:43:02
 * Copyright (c) 2017, 9459397@qq.com All Rights Reserved.
 *
 */

package com.demo.validator;

import com.demo.common.model.Blog;
import com.jfinal.core.Controller;
import com.jfinal.upload.UploadFile;
import com.jfinal.validate.Validator;

/**
 * ClassName: FormValidator <br/>
 * Function: TODO ADD FUNCTION. <br/>
 * Reason: TODO ADD REASON(可选). <br/>
 * Date: 2017年1月4日 上午9:08:53 <br/>
 *
 * @author michael  郑鸿
 * @version 
 * @since JDK 1.8
 */
public class FormValidator extends Validator {

	/**
	 * 参数校验方法.
	 * @see com.jfinal.validate.Validator#validate(com.jfinal.core.Controller)
	 */
	@Override
	protected void validate(Controller c) {
		/**
		 * 编写校验规则
		 */
		c.getFile("img");//非常重要，一定要先取出文件，否则取不到参数值
		validateRequiredString("blog.title", "titleMsg", "标题不能为空！");
		
	}

	/**
	 * 错误处理方法.
	 * @see com.jfinal.validate.Validator#handleError(com.jfinal.core.Controller)
	 */
	@Override
	protected void handleError(Controller c) {
		//String actionKye = getActionKey();
		c.keepModel(Blog.class);//保存上一次表单提交记录，？？？不起作用
		c.renderJsp("form.jsp");
		
	}

}

